#include <stdio.h>
#include <stdlib.h>

typedef struct ListNode {
    int val;
    struct ListNode *next;
} ListNode;

ListNode* createNode(int val) {
    ListNode *newNode = (ListNode*)malloc(sizeof(ListNode));
    if (!newNode) {
        exit(1);
    }
    newNode->val = val;
    newNode->next = NULL;
    return newNode;
}

ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
    // 合并链表 补全该函数
    ListNode *merged=NULL,*current=NULL;
    if (l1==NULL || l2==NULL){
        if (l1==NULL)return l2;
        else return l1; 
    }
    while (l1!=NULL&&l2!=NULL) {
        if (l1->val<=l2->val) {
            if (merged==NULL) {
                merged=l1;
                current=merged;
            } else {
                current->next=l1;
                current=current->next;
            }
            l1=l1->next;
        } else {
            if (merged==NULL) {
                merged=l2;
                current=merged;
            } else {
                current->next=l2;
                current=current->next;
            }
            l2=l2->next;
        }
    }
    if (l1!=NULL){
        current->next=l1;
    }
    if (l2!=NULL){
        current->next=l2;
    }
    return merged;
}

int main() {
    int n, m, val;
    ListNode *l1 = NULL, *l2 = NULL, *l1Tail = NULL, *l2Tail = NULL;

    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &val);
        if (l1 == NULL) {
            l1 = createNode(val);
            l1Tail = l1;
        } else {
            l1Tail->next = createNode(val);
            l1Tail = l1Tail->next;
        }
    }

    scanf("%d", &m);
    for (int i = 0; i < m; ++i) {
        scanf("%d", &val);
        if (l2 == NULL) {
            l2 = createNode(val);
            l2Tail = l2;
        } else {
            l2Tail->next = createNode(val);
            l2Tail = l2Tail->next;
        }
    }

    ListNode *merged = mergeTwoLists(l1, l2);

    while (merged != NULL) {
        printf("%d ", merged->val);
        merged = merged->next;
    }
    printf("\n");

    return 0;
}